<?php

class Xoops_User extends Abstract_User {

	var $mHandler;

	function Xoops_User()
	{
		$this->mHandler =& xoops_gethandler('member');
		$this->modHandler =& xoops_gethandler('module');
		$this->module =& $this->modHandler->getByDirname('xoopsgallery');
	}

	function loadByUid($uid) {

		$user =& $this->mHandler->getUser($uid);
		if (is_object($user)) {
			$this->uid             = $uid;
			$this->username        = $user->getVar('uname');
			$this->password        = $user->getVar('pass');
			$this->isAdmin         = (!$user->isAdmin($this->module->getVar('mid'))) ? 0 : 1;
			$this->canCreateAlbums = $this->isAdmin;
			$this->fullname        = ($user->getVar('name') != '') ? $user->getVar('name') : $this->username;
			$this->email           = $user->getVar('email');
		} else {
			$this->uid = $uid;
			$this->username = "UNKNOWN_USER_".$uid;
			$this->isAdmin = false;
			$this->fullname = "Unknown User (UID $uid)";
		}
	}

	function loadByUserName($uname) {
		
		$user =& $this->mHandler->getUsers(new Criteria('uname', $uname));

		$this->uid             = $user[0]->getVar('uid');
		$this->username        = $uname;
		$this->password        = $user[0]->getVar('pass');
		$this->isAdmin         = (!$user[0]->isAdmin($this->module->getVar('mid'))) ? 0 : 1;
		$this->canCreateAlbums = $this->isAdmin;
		$this->fullname        = ($user[0]->getVar('name') != '') ? $user[0]->getVar('name') : $uname;
		$this->email           = $user[0]->getVar('email');
	}

}
?>